package com.seguriapp.gwt.client;

import java.util.Date;
import java.util.List;

import javax.inject.Singleton;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.seguriapp.entities.MenuLink;
import com.seguriapp.gwt.client.PrincipalHeaderPresenter.Display;

@Singleton
public class PrincipalPage extends Composite implements PrincipalPagePresenter.Display {

  interface PrincipalPageUiBinder extends UiBinder<Widget, PrincipalPage> {
  }

  private static PrincipalPageUiBinder uiBinder = GWT.create(PrincipalPageUiBinder.class);

  @UiField
  HTMLPanel principalPage;
  @UiField
  SimplePanel panelCentral;
  @UiField
  DivElement menuDiv;
  @UiField
  DivElement contenidoDiv;
  @UiField
  PrincipalHeader cabecera;
  @UiField
  MenuPrincipal menu;

  @SuppressWarnings("unused")
  private PrincipalPagePresenter presenter;

  @Inject
  public PrincipalPage() {
    initWidget(uiBinder.createAndBindUi(this));
  }

  public AcceptsOneWidget getPanelCentral() {
    return panelCentral;
  }

  public Widget getPanelCentralAsWidget() {
    return panelCentral;
  }

  public void setPresenter(final PrincipalPagePresenter principalPagePresenter) {
    presenter = principalPagePresenter;
  }

  public Display getCabecera() {
    return cabecera;
  }

  public MenuPresenter.Display getMenu() {
    return menu;
  }

  public void setLoggedInUserInfo(final String username, final Date lastDateLoggedIn, final boolean administrator, final List<MenuLink> menuList) {
    cabecera.setLoggedInUserInfo(username, lastDateLoggedIn);
    menu.setDatosMenu(menuList);
  }

  public void removeUserInformation() {
    cabecera.removeUserInformation();
  }

}
